﻿using System.Windows;
using System.Windows.Controls;
using Dsl.Ped.Framework.Messages;

namespace Dsl.Ped.Desktop.Modules.ErrorViewer
{
    public class IconTemplateSelector : DataTemplateSelector
    {

        /// <summary>
        /// Returns an appropriate data template for the <see cref="NotifyMessage"/> object. 
        /// </summary>
        /// <param name="item">The data object for which to select the template.</param>
        /// <param name="container">The data-bound object.</param>
        /// <returns>Returns a DataTemplate or null. The default value is null. </returns>        
        public override System.Windows.DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            if (item != null && item is NotifyMessage)
            {
                NotifyMessage fbiMessage = item as NotifyMessage;
                FrameworkElement element = container as FrameworkElement;

                switch (fbiMessage.Type)
                {
                    case NotifyType.Error:
                        // Get the template named 'errorCellTemplate' from the resource file
                        return element.FindResource("errorCellTemplate") as DataTemplate;
                    case NotifyType.Info:
                        // Get the template named 'infoCellTemplate' from the resource file
                        return element.FindResource("infoCellTemplate") as DataTemplate;
                    case NotifyType.Warning:
                        // Get the template named 'warningCellTemplate' from the resource file
                        return element.FindResource("warningCellTemplate") as DataTemplate;
                    default:
                        return null;
                }
            }
            else
            {
                return null;
            }
            return null;
        }
    }
}
